package com.example.flower_shop.controller;

import com.example.flower_shop.service.CategoryService;
import com.example.flower_shop.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/test")
public class TestController {

    @Autowired
    private CategoryService categoryService;

    @GetMapping("/public")
    public String publicEndpoint() {
        return "This is a public endpoint";
    }

    @GetMapping("/private")
    public String privateEndpoint() {
        return "This is a private endpoint";
    }

    @GetMapping("/init-categories")
    public Result<String> initCategories() {
        try {
            // 创建鲜花分类
            if (!categoryService.existsByName("鲜花")) {
                categoryService.createCategory("鲜花", "各类新鲜花束、花篮等");
            }

            // 创建绿植分类
            if (!categoryService.existsByName("绿植")) {
                categoryService.createCategory("绿植", "室内外观赏植物、盆栽等");
            }

            return Result.success("分类初始化成功");
        } catch (Exception e) {
            return Result.error("分类初始化失败：" + e.getMessage());
        }
    }
}